package org.example.JUC.threadLocal;

import javax.swing.tree.TreeNode;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @description:
 * @author: farprt
 * @create: 2022-08-19 01:15
 **/
public class threadLocalTest {

    static ThreadLocal<String> localVariable=new ThreadLocal<>();

    static void print(String str){
        System.out.println(str+":"+localVariable.get());
        localVariable.remove();
    }

    public static void main(String[] args) {
        Thread threadOne=new Thread(()->{
            localVariable.set("threadOne local variable");
            print("threadOne");
            System.out.println("threadOne remove after"+":"+localVariable.get());
        });

        Thread threadTwo=new Thread(()->{
            localVariable.set("threadTwo local variable");
            print("threadTwo");
            System.out.println("threadTwo remove after"+":"+localVariable.get());

        });
        threadOne.start();
        threadTwo.start();
    }
}